<?php

namespace app\controller;

use app\BaseController;
use think\Request;
use app\service\BankService;
use Exception;

class Bank extends BaseController
{    
    protected $middleware = [
        \app\middleware\LoginCheck::class
    ];
    protected $request;
    protected $bankService;
    public function __construct(Request $request,BankService $bankService)
    {       
        $this->request = $request;
        $this->bankService = $bankService;
    }    

    public function list()
    {       
        try {   
            $params = $this->request->param();                
            $data = $this->bankService->list($params);
        } catch (Exception $e) {
            return $this->error($e->getMessage());
        }

        return $this->success($data);
    } 
    
    public function all()
    {       
        try {            
            $data = $this->bankService->all();
        } catch (Exception $e) {
            return $this->error($e->getMessage());
        }

        return $this->success($data);
    }
    
    public function info()
    {       
        try {     
            $params = $this->request->param();       
            $data = $this->bankService->info($params['id']);
        } catch (Exception $e) {
            return $this->error($e->getMessage());
        }

        return $this->success($data);
    } 
    
    public function save()
    {       
        try {    
            $params = $this->request->param();  
            $data = $this->bankService->save($params);
        } catch (Exception $e) {
            return $this->error($e->getMessage());
        }

        return $this->success($data);
    }

    public function delete()
    {       
        try {    
            $params = $this->request->param();  
            $data = $this->bankService->delete($params);
        } catch (Exception $e) {
            return $this->error($e->getMessage());
        }

        return $this->success($data);
    }
}
